package com.gxa.uhome.controller;

import com.gxa.uhome.pojo.PhoneAndAgreement;
import com.gxa.uhome.pojo.Station;
import com.gxa.uhome.service.LogService;
import com.gxa.uhome.service.PAAService;
import com.gxa.uhome.util.JsonResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: fanyouzhao
 * @date: 11:41 2021/6/11
 */
@RestController
@CrossOrigin
@RequestMapping("/paa")
@Api(tags = "PAA客服电话和用户协议", produces = "application/json;charset=UTF-8")
public class PAAController {
    @Resource
    PAAService paaService;
    @Resource
    LogService logService;

    JsonResult jsonResult = null;

    @ApiOperation(value = "获得客服电话和用户协议")
    @GetMapping(value = "/select", produces = "application/json;charset=UTF-8")
    public JsonResult select() {
        PhoneAndAgreement select = paaService.select();
        jsonResult = new JsonResult("1", "查询成功", select);
        return jsonResult;
    }

    @ApiOperation(value = "修改客服电话和用户协议")
    @PostMapping("/update")
    public JsonResult update(@RequestBody @ApiParam(name = "PhoneAndAgreement客服电话和用户协议的对象",
            value = "传入json格式") PhoneAndAgreement phoneAndAgreement, HttpSession httpSession) {
        boolean update = paaService.update(phoneAndAgreement);
        Integer adminId = (Integer) httpSession.getAttribute("AdminId");
        if (update) {
            jsonResult = new JsonResult("1", "修改成功");
            logService.insert("修改客服电话和用户协议", adminId,
                    "修改客服电话和用户协议");
        } else {
            jsonResult = new JsonResult("0", "修改失败");
        }
        return jsonResult;
    }
}